#!/bin/sh --

#
# Build a mutt release.
#
# This used to be part of the main Makefile, but is better handled
# by a shell script.
#
# Note that this script won't work for you.  I'm including it with 
# the distribution for the sake of completeness.
#
# Thomas Roessler <roessler@does-not-exist.org> Mon,  8 Nov 1999 22:32:41 +0100
#

set -e

if test "$1" = "-nodiff" ; then
	diff=no
else
	diff=yes
fi


devel="devel/"	# comment out for the stable branch

# test for uncommitted changes
if hg id | grep -q '+'
then
  echo "Uncommitted changes"
  exit 1
fi

# update the source

hg update

# Do automated security checks

./check_sec.sh || exit 1

# bump the version number, and calculate the tags

OVERSION="`cat VERSION`" 
OTAG="mutt-`echo $OVERSION | tr . -`-rel" 

echo $OVERSION | awk -F . '{printf("%d.%d.%d\n", $1, $2, $3 + 1);}' > VERSION 
${VISUAL:-vi} VERSION

VERSION="`cat VERSION`" 
TAG="mutt-`echo $VERSION | tr . -`-rel" 

#echo 'const char *ReleaseDate = "'`date +%Y-%m-%d`'";' > reldate.h

# now, prepare the distribution tar balls

#automake
#touch configure.in
make config.status
./config.status
make update-doc
make update-changelog
(cd po && make update-po)

# build them

make dist

# commit and tag the release

hg commit -m "automatic post-release commit for mutt-${VERSION}"
#make commit-changelog 
hg tag ${TAG}

# build the diff between the two releases

if test "$diff" = yes
then
  hg diff -r ${OTAG} -r ${TAG} | gzip -9 \
		> diff-${OVERSION}-${VERSION}.gz
fi

# sign the various files

# DISTFILES="mutt-${VERSION}.tar.gz mutt-${VERSION}i.tar.gz diff-${OVERSION}i-${VERSION}i.gz"
DISTFILES="mutt-${VERSION}.tar.gz"

if test "$diff" = yes ; then
	DISTFILES="$DISTFILES diff-${OVERSION}-${VERSION}.gz"
fi

for f in $DISTFILES; do
	gpg -ba $f
	chmod 644 $f.asc
done

for f in $DISTFILES ; do
	scp $f $f.asc trithemius.gnupg.org:/home/ftp/mutt/${devel}
done

hg sign -m"mutt-${VERSION} signed" ${TAG}

# Finally, announce the new mutt to the public

# mutt -s "[Announce] mutt-${VERSION} is out" mutt-dev@mutt.org

